package cn.maszy.service.impl.systemsetting;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.DateUtils;
import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.systemsetting.B_T_Sys_OperatingLogsMapper;
import cn.maszy.model.systemsetting.B_T_Sys_OperatingLogs;
import cn.maszy.model.systemsetting.B_T_Sys_OperatingLogsExample;
import cn.maszy.model.systemsetting.B_T_Sys_OperatingLogsExample.Criteria;
import cn.maszy.service.systemsetting.B_T_Sys_OperatingLogsService;
@Service
public class B_T_Sys_OperatingLogsServiceImpl implements B_T_Sys_OperatingLogsService {

	@Autowired 
	private B_T_Sys_OperatingLogsMapper b_T_Sys_OperatingLogsMapper;
	
	public int update(B_T_Sys_OperatingLogs b_T_Sys_OperatingLogs) {
		// TODO Auto-generated method stub
		if(b_T_Sys_OperatingLogs.getLogsId()==null||"".equals(b_T_Sys_OperatingLogs.getLogsId())){
			 b_T_Sys_OperatingLogs.setLogsId(UUID.randomUUID().toString());
			 b_T_Sys_OperatingLogs.setIsDelete(0);
			 b_T_Sys_OperatingLogs.setCreateTime(new Date());
			 b_T_Sys_OperatingLogs.setCreateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Sys_OperatingLogsMapper.insert(b_T_Sys_OperatingLogs);
		 }else{
			 b_T_Sys_OperatingLogs.setUpdateTime(new Date());
			 b_T_Sys_OperatingLogs.setUpdateUser(SessionFactory.getSessionUserRealNam());
			 return b_T_Sys_OperatingLogsMapper.updateByPrimaryKeySelective(b_T_Sys_OperatingLogs);
		 }
	}

	public B_T_Sys_OperatingLogs selectOne(String logsid) {
		// TODO Auto-generated method stub
		B_T_Sys_OperatingLogs record=b_T_Sys_OperatingLogsMapper.selectByPrimaryKey(logsid);
		if("".equals(logsid)){
			record = new B_T_Sys_OperatingLogs();
		}
		return record;
	}

	public Pager<B_T_Sys_OperatingLogs> selectList(B_T_Sys_OperatingLogs b_T_Sys_OperatingLogs,Pager<B_T_Sys_OperatingLogs> pager,String strattime,String endtime,String flag,String taskid) {
		// TODO Auto-generated method stub
		B_T_Sys_OperatingLogsExample example=new B_T_Sys_OperatingLogsExample();
		Criteria criteria = example.createCriteria();
			if(b_T_Sys_OperatingLogs!=null){
			if(b_T_Sys_OperatingLogs.getOperatingName()!=null && !"".equals(b_T_Sys_OperatingLogs.getOperatingName())){
				criteria.andOperatingNameLike("%"+b_T_Sys_OperatingLogs.getOperatingName()+"%");
			}
			if(b_T_Sys_OperatingLogs.getOperatingContent() != null && !"".equals(b_T_Sys_OperatingLogs.getOperatingContent())){
				criteria.andOperatingContentLike("%"+b_T_Sys_OperatingLogs.getOperatingContent()+"%");
			}
		}
		if(strattime!=null&&!"".equals(strattime)){
			criteria.andOperatingTimeGreaterThanOrEqualTo(strattime +" 00:00:00");
		}
		if(endtime!=null&&!"".equals(endtime)){
			criteria.andOperatingTimeLessThanOrEqualTo(endtime+" 23:59:59");
		}
		if("2".equals(flag)){
				criteria.andOperatingNameEqualTo(SessionFactory.getSessionUserRealNam());
		}
		if(null != taskid){
			criteria.andTaskIdEqualTo(taskid);
		}
		criteria.andIsDeleteEqualTo(0);
		example.or(criteria);
		int totalCount=new B_T_Sys_OperatingLogsServiceImpl().count(example,b_T_Sys_OperatingLogsMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		// 取得总的记录条数
		List<B_T_Sys_OperatingLogs>  list=b_T_Sys_OperatingLogsMapper.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
	}

	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		for (String id : checkIds.split(", ")) {
			b_T_Sys_OperatingLogsMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	public int count(B_T_Sys_OperatingLogsExample example,B_T_Sys_OperatingLogsMapper b_T_Sys_OperatingLogsMapper) {
		// TODO Auto-generated method stub
		return b_T_Sys_OperatingLogsMapper.countByExample(example);
	}

}
